using System;
using System.Collections.Generic;
using System.Text;
using Accountability4net;
using Accountability4net;

namespace Accountability4net.MemoryMonengineProvider
{
    public class MemoryTransaction : BaseTransaction
    {

        public MemoryTransaction(DateTimeOffset timestamp)
        {
            Timestamp = timestamp;
        }

        #region ITransaction Members
        public override void Commit()
        {
            base.Commit();
            foreach (IAction action in this)
            {
                switch (action.Type)
                {
                    case ActionType.CREDIT:
                        action.Account.Credit(action.Amount, this);
                        break;
                    case ActionType.DEBIT:
                        action.Account.Debit(action.Amount, this);
                        break;
                };
            }
            isCommitted_ = true;
        }

        private DateTimeOffset timestamp_;
        public override DateTimeOffset Timestamp
        {
            get
            {
                return timestamp_;
            }
            set
            {
                timestamp_ = value;
            }
        }

        private string description_;
        public override string Description
        {
            get
            {
                return description_;
            }
            set
            {
                description_ = value;
            }
        }

        private bool isCommitted_;
        public override bool IsCommitted
        {
            get { return isCommitted_; }
        }

        private Guid id_;
        public override Guid ID
        {
            get
            {
                return id_;
            }
            set
            {
                id_ = value;
            }
        }

        #endregion
    }
}
